home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / os2 / dialogs.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  14KB  |  375 lines

  1. #ifdef INCRCSDATA
  2. static char RCSid[]="$Id: dialogs.c%v 3.50 1993/07/09 05:35:24 woo Exp $" ;
  3. #endif
  4.  
  5. /****************************************************************************
  6.  
  7.     PROGRAM: gnupmdrv
  8.     
  9.         Outboard PM driver for GNUPLOT 3.3
  10.  
  11.     MODULE:  dialogs.c  Dialog procedures for gnupmdrv 
  12.         
  13. ****************************************************************************/
  14.  
  15. /*
  16.  * PM driver for GNUPLOT
  17.  * Copyright (C) 1992   Roger Fearick
  18.  *
  19.  * Permission to use, copy, and distribute this software and its
  20.  * documentation for any purpose with or without fee is hereby granted, 
  21.  * provided that the above copyright notice appear in all copies and 
  22.  * that both that copyright notice and this permission notice appear 
  23.  * in supporting documentation.
  24.  *
  25.  * Permission to modify the software is granted, but not the right to
  26.  * distribute the modified code.  Modifications are to be distributed 
  27.  * as patches to released version.
  28.  *  
  29.  * This software is provided "as is" without express or implied warranty.
  30.  * 
  31.  *
  32.  * AUTHOR
  33.  * 
  34.  *   Gnuplot driver for OS/2:  Roger Fearick
  35.  * 
  36.  * Send your comments or suggestions to 
  37.  *  info-gnuplot@dartmouth.edu.
  38.  * This is a mailing list; to join it send a note to 
  39.  *  info-gnuplot-request@dartmouth.edu.  
  40.  * Send bug reports to
  41.  *  bug-gnuplot@dartmouth.edu.
  42. **/
  43.  
  44. #define INCL_PM
  45. #define INCL_WIN
  46. #define INCL_DEV
  47. #define INCL_SPL
  48. #define INCL_SPLDOSPRINT
  49. #define INCL_WINDIALOGS
  50. #define INCL_WINBUTTONS
  51. #define INCL_WINSYS
  52. #define INCL_WINFRAMEMGR
  53. #define INCL_WINPOINTERS
  54. #define INCL_WINTRACKRECT
  55. #define INCL_WINENTRYFIELDS
  56. #define INCL_WINWINDOWMGR
  57. #include <os2.h>
  58. #include <math.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include "gnupmdrv.h"
  63.  
  64. /* struct for printer capabilities */
  65.  
  66. static struct { 
  67.     long    lTech ;     // printer technology
  68.     long    lVer ;      // driver version
  69.     long    lWidth ;    // page width in pels
  70.     long    lHeight ;   // page height in pels
  71.     long    lWChars ;   // page width in chars    
  72.     long    lHChars ;   // page height in chars    
  73.     long    lHorRes ;   // horizontal resolution pels / metre
  74.     long    lVertRes ;  // vertical resolution pels / metre
  75.     } prCaps ;
  76.  
  77. MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  78. /*
  79. **  Query print area and printer setup
  80. */
  81.     {
  82.     static PQPRINT pqp = NULL ;
  83.     static SWP     swp ;    
  84.     TRACKINFO   ti ;
  85.     RECTL       rectlBox ;
  86.     HDC         hdc ;
  87.     ULONG       ulStyle ;
  88.     char        *psz ;
  89.  
  90.     switch ( usMsg ) {
  91.  
  92.         case WM_INITDLG :
  93.                                    
  94.             pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
  95.             if( pqp->caps & QP_CAPS_FILE ) {
  96.                 ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  97.                                                QWL_STYLE ) ;
  98.                 WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  99.                                    QWL_STYLE, ulStyle ^ DT_HALFTONE  ) ;
  100.                 }
  101.             else {
  102.                 WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
  103.                             EM_SETREADONLY, (MPARAM)TRUE, 0L ) ;
  104.                 }
  105.              
  106.         case WM_USER_SET_DATA :
  107.  
  108.             psz = *pqp->piPrinter->pszComment ? pqp->piPrinter->pszComment :
  109.                                         pqp->piPrinter->pszName ;
  110.             WinSetDlgItemText( hwnd, IDD_PRINTNAME, psz ) ;
  111.             WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
  112.             WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
  113.             WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  114.             WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  115.             WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  116.                                 &rectlBox ) ;
  117.             WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  118.                                &swp ) ;
  119.             rectlBox.xRight = rectlBox.yTop * pqp->xsize/pqp->ysize ;
  120.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  121.                              NULLHANDLE, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
  122.             rectlBox.xRight *= pqp->xfrac ;
  123.             rectlBox.yTop *= pqp->yfrac ;
  124.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  125.                              NULLHANDLE, 
  126.                              swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
  127.                              (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  128.             break ;
  129.             
  130.         case WM_COMMAND :
  131.  
  132.             switch ( SHORT1FROMMP(mp1) ) {
  133.  
  134.                 case DID_OK:
  135.                     WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
  136.                     WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
  137.  
  138.                     if( pqp->caps & QP_CAPS_FILE ) {
  139.                         WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, pqp->szFilename ) ;
  140.                         }
  141.                     break ;
  142.  
  143.                 case IDD_QPRSETPR:   /* printer setup */
  144.                     if( SetPrinterMode( hwnd, pqp->piPrinter ) == 1 ) {
  145.                         if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ), 
  146.                                                   pqp->piPrinter, 
  147.                                                   OD_INFO, 
  148.                                                   NULL )) != DEV_ERROR ) {
  149.                             DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
  150.                             DevCloseDC( hdc ) ;
  151.                             pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
  152.                             pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
  153.                             WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
  154.                             }
  155.                         }
  156.                     return 0L ;
  157.  
  158.                 case IDD_QPRTRACK :     /* track plot area */
  159.                     WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  160.                                         &rectlBox ) ;
  161.                     ti.cxBorder = ti.cyBorder = 2 ;
  162.                     ti.cxGrid = ti.cyGrid = 0 ;
  163.                     ti.cxKeyboard = ti.cyKeyboard = 2 ;
  164.                     ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
  165.                     ti.rclBoundary = rectlBox ;
  166.                     ti.ptlMaxTrackSize.x = rectlBox.xRight ;
  167.                     ti.ptlMaxTrackSize.y = rectlBox.yTop ;
  168.                     ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
  169.                     ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
  170.                     ti.rclTrack.xLeft = 0 ;
  171.                     ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
  172.                     ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
  173.                     WinSetPointer( HWND_DESKTOP, 
  174.                                    WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
  175.                     WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  176.                                   NULL, 
  177.                                   &ti ) ;
  178.                     pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
  179.                     pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
  180.                     rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
  181.                     rectlBox.xRight = ti.rclTrack.xRight ;
  182.                     WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  183.                                      NULLHANDLE, 
  184.                                      swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
  185.                                      (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  186.                     WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  187.                     WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  188.                     return 0L ;
  189.                     
  190.                 default:
  191.                     break ;
  192.                 }
  193.                 
  194.          default:
  195.             break ;
  196.             }
  197.         /* fall through to the default control processing */
  198.  
  199.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  200.     }
  201.  
  202. MRESULT EXPENTRY QPrintersDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  203. /*
  204. **  Query printers and allow selection
  205. */
  206.     {
  207.     static HWND hwndLB ;
  208.     static PPRQINFO3 pprq ;
  209.     static int cPrinters ;
  210.     static USHORT usItem ;
  211.     static char *szPrinterName ;
  212.     int i, iSelect ;
  213.     char *psz ;
  214.  
  215.     switch ( usMsg ) {
  216.  
  217.         case WM_INITDLG :
  218.  
  219.             szPrinterName = (char*) PVOIDFROMMP( mp2 ) ;
  220.             iSelect = 0 ;
  221.             GetPrinters( &pprq, &cPrinters ) ;
  222.             hwndLB = WinWindowFromID( hwnd, IDD_QPRSLIST ) ;
  223.             for( i=0; i<cPrinters;i++ ) {
  224.                 psz = *pprq[i].pszComment ? pprq[i].pszComment :
  225.                                             pprq[i].pszName ;
  226.                 WinSendMsg( hwndLB,
  227.                             LM_INSERTITEM,
  228.                             (MPARAM)LIT_END,
  229.                             MPFROMP(psz) ) ;
  230.                 if( strcmp( pprq[i].pszName, szPrinterName ) == 0 )
  231.                     iSelect = i ;
  232.                 } 
  233.                 
  234.             WinSendMsg( hwndLB,
  235.                         LM_SELECTITEM,
  236.                         MPFROMSHORT( iSelect ),
  237.                         (MPARAM)TRUE ) ;
  238.        
  239.             break ;
  240.  
  241.         case WM_COMMAND :
  242.  
  243.             switch ( SHORT1FROMMP(mp1) ) {
  244.  
  245.                 case DID_OK:
  246.                     strcpy( szPrinterName, pprq[usItem].pszName ) ;
  247.                 case DID_CANCEL:
  248.                     free( pprq ) ;
  249.                     break ;
  250.                 }
  251.             break ;
  252.  
  253.         case WM_CONTROL:
  254.         
  255.             if( SHORT1FROMMP( mp1 ) == IDD_QPRSLIST ) {
  256.                 if( SHORT2FROMMP( mp1 ) == LN_SELECT  ) {
  257.                     usItem = (ULONG)WinSendMsg( hwndLB,
  258.                                 LM_QUERYSELECTION,
  259.                                 0L,
  260.                                 0L ) ;
  261.                     }
  262.                 }
  263.  
  264.         default:
  265.             break ;
  266.         }
  267.         /* fall through to the default control processing */
  268.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  269.     }
  270.     
  271. int GetPrinters( PPRQINFO3 *pprq, int *pcTot  )
  272. /*
  273. ** get a list of printers
  274. */
  275.     {
  276.     ULONG rc ;
  277.     ULONG cQueues, cbData ;
  278.     
  279.     rc = SplEnumQueue( NULL, 3, NULL, 0, &cQueues, pcTot, &cbData, NULL ) ;
  280.    
  281.     if( *pcTot == 0 ) { /* no printers */
  282.         *pprq == NULL ;
  283.         return 0 ;
  284.         }
  285.     *pprq = malloc( cbData ) ;
  286.     rc = SplEnumQueue( NULL,
  287.                        3,
  288.                        *pprq,
  289.                        cbData,
  290.                        &cQueues,
  291.                        pcTot,
  292.                        &cbData,
  293.                        NULL ) ;
  294.     return *pcTot ;
  295.     }
  296.  
  297. MRESULT EXPENTRY PauseMsgDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  298. /*
  299. **  Pause message dialog box proc
  300. */
  301.     {
  302.     static PSWP pswp = NULL ;
  303.     switch ( usMsg ) {
  304.  
  305.         case WM_INITDLG :
  306.                 /* set the position so user can move out the way, and
  307.                    have it come back there next time */
  308.             if( pswp != NULL ) 
  309.                 WinSetWindowPos( hwnd, HWND_TOP, pswp->x, pswp->y,
  310.                                  0, 0, SWP_MOVE ) ; 
  311.             WinSetDlgItemText( hwnd, IDD_PAUSETEXT, (char*) PVOIDFROMMP( mp2 ) ) ;
  312.             break ;
  313.  
  314.         case WM_COMMAND :
  315.             switch ( SHORT1FROMMP(mp1) ) {
  316.                 case DID_OK:
  317.                 case DID_CANCEL:
  318.                     WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
  319.                                 WM_PAUSEEND, 
  320.                                 SHORT1FROMMP(mp1)==DID_OK?(MPARAM)1L:0L, 
  321.                                 0L ) ;
  322.                     if( pswp == NULL ) pswp = (PSWP)malloc( sizeof(SWP) ) ;
  323.                     WinQueryWindowPos( hwnd, pswp ) ;
  324.                     WinDismissDlg( hwnd, 0 ) ; 
  325.                     break ;
  326.                 default:
  327.                     break ;
  328.                 }
  329.         default:
  330.             break ;
  331.         }
  332.         /* fall through to the default control processing */
  333.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  334.     }
  335.     
  336. void WinSetDlgItemFloatF( HWND hwnd, USHORT usID, int nDec, float flValue )
  337. /*
  338. ** A function microsoft forgot ( in v1.1) , see WinSet...Short
  339. */
  340.     {
  341.     char achBuffer [ 34 ], *szCvt ; // default string field size ...
  342.     int  iDec ;
  343.     int  iSign ;
  344.     char fmt[32] ;
  345.     sprintf( fmt, "%%12.%df", nDec ) ;
  346.     sprintf( achBuffer, fmt, flValue ) ;
  347.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  348.     }
  349.  
  350. void WinSetDlgItemFloat( HWND hwnd, USHORT usID, float flValue )
  351. /*
  352. ** A function microsoft forgot ( in v1.1) , see WinSet...Short
  353. */
  354.     {
  355.     char achBuffer [ 34 ] ; // default string field size ...
  356.     char fmt[10] ;
  357.     sprintf( fmt, "%%12.%df", 4 ) ;
  358.     sprintf( achBuffer, fmt, flValue ) ;
  359.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  360.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  361.     }
  362.  
  363. void WinQueryDlgItemFloat( HWND hwnd, USHORT usID, float *pflValue )
  364. /*
  365. ** A function microsoft forgot ( in v1.1) , see WinQ...Short
  366. */
  367.     {
  368.     char achBuffer [ 34 ] ; // default string field size ...
  369.     ULONG ulTemp ;
  370.     
  371.     WinQueryDlgItemText( hwnd, usID, 34, achBuffer ) ;
  372.     *pflValue = (float) atof( achBuffer ) ;
  373.     }
  374.  
  375.